<% layout('/layout/default.html', {title: '待办任务', libs: ['layui','icheck']}){ %>
<div class="main-content">
	<div class="box box-main">
		<div class="card-header">
			<i class="fa fa-sitemap"></i> 待办任务
			<div class="header-tools float-right">
				<a href="#" class="btn btn-default btn-sm" id="btnSearch" title="查询"><i class="fa fa-filter"></i> 查询</a>
			</div>
		</div>
		<div class="container-fluid">
			<form id="searchForm" action="${ctx}/act/task/todoData" class="form-inline d-none">
				<div class="form-group">
					<label class="control-label">流程分类：</label>
					<div class="control-inline">
						<#form:select path="category" name="label" data="getDictList:act_category" class="form-control select2bs4" />
					</div>
				</div>
				<div class="form-group">
					<label class="control-label">发起人：</label>
					<div class="control-inline">
						<#form:select id="userid" path="startBy" name="name" value="loginName" data="${userList}" class="form-control select2bs4" />
					</div>
				</div>
				<div class="form-group">
					<label class="control-label">创建时间：</label>
					<div class="control-inline">
						<input id="beginDate" name="beginDate" maxlength="64" readonly="readonly" class="form-control form-control-sm"
							   value="" onclick="WdatePicker({dateFmt:'yyyy-MM-dd',isShowClear:true});" /> -
						<input id="endDate" name="endDate" maxlength="64" readonly="readonly" class="form-control form-control-sm"
							   value="" onclick="WdatePicker({dateFmt:'yyyy-MM-dd',isShowClear:true});" />
					</div>
				</div>
				<div class="form-group">
					<button type="submit" class="btn btn-success btn-sm">查询</button>
					<button id="reset" type="reset" class="btn btn-default btn-sm">重置</button>
				</div>
			</form>
			<table id="btGrid"></table>
		</div>
	</div>
</div>
<% } %>
<script>
$.fn.select2.defaults.set('width', '200px');
$('#reset').click(function(){
	$('#category').val(null).trigger("change");
	$('#userid').val(null).trigger("change");
});
//初始化layui-table对象
$('#btGrid').BTGrid({
	searchForm: $("#searchForm"),
	columnModel: [
		{title:'流程名称', field:'procDefname'},
        {title:'流程发起人', field:'startUser.name',templet:function(row){
			return row.startUser.name;
		}},
		{title:'当前环节', templet: function(row){
			return '<a href="${ctx}/act/task/diagramViewer?definitionId='+row.procDefId+ '&instanceId=' + row.procInsId +'" class="btnList" title="流程图查看" data-type="diagram">' +row.taskName+ '</a>'
		}},
		{title:'流程版本', templet: function(row){
			return "V:" + row.procDefversion;
		}},
		{title:'创建时间', field:'createTime',templet: function (row) {
				if (row.createTime){   // data不为空进行转换
					return (new Date(row.createTime)).Format("yyyy-MM-dd hh:mm:ss");
				} else {
					return ''; //data为空时不转换
				}
		}},
		{title:'操作', templet: function(row){

			var actions = [];
			if(row.assignee == null || row.assignee.length == 0) {
				actions.push('<a href="${ctx}/act/task/claim?taskId=' + row.taskId+ '" class="btn btn-xs btn-success btnList" title="签收任务" data-confirm="确认要签收该任务吗？">签收任务</a>&nbsp;');
			} else {
				actions.push('<a href="/act/flowForm/common?taskId=' + row.taskId+ '&taskDefKey=' + row.taskDefKey + '&procInsId=' + row.procInsId + '&procDefId=' + row.procDefId + '&status=' + row.status + '" class="btn btn-xs btn-success btnList" title="任务办理" >任务办理</a>&nbsp;');
			}
			<%if(hasPermi("act:process:edit")){%>
				if(row.executionId == "") {
					actions.push('<a href="${ctx}/act/task/deleteTask?taskId=' + row.taskId +'&reason=" class="btn btn-xs btn-danger btnList" title="删除" data-prompt="输入删除原因并确认："><i class="far fa-trash-alt"></i></a>&nbsp;');
				}
			<%}%>

			return actions.join('');
		}}
	],
	// 加载成功后执行事件
	ajaxSuccess: function(data){

	}
});
</script>